package wd

import (
	"app/wd/goredis"
	"fmt"

	"github.com/redis/go-redis/v9"
)

// Redis 链接信息
type _Redis struct {
	Conn *goredis.Conn
	DB   *redis.Client
}

// initRedis 初始化redis
func initRedis() {
	conf := App.Config.GetStringMapString("redis")
	dbConf := &goredis.Conn{
		ConfName: conf["conf_name"],
		Host:     conf["host"],
		Port:     conf["port"],
		Pwd:      conf["pwd"],
		Database: conf["database"],
	}
	// 连接数据库
	db, err := goredis.NewClient(dbConf, App.SysLog)
	if err != nil {
		panic(fmt.Errorf("fatal error db connection: %w", err))
	}
	App.Redis[dbConf.ConfName] = &_Redis{
		Conn: dbConf,
		DB:   db,
	}
}
